package hypeerweb;

import java.io.Serializable;

/**
 *
 * <pre>
 *  <b>Domain:</b>
 *      delegate:             Node
 * </pre>
 *
 * @author Brent Mouritsen AND <br>
 * Chase White
 */

public abstract class NodeDelegate implements Serializable {
	private static final long serialVersionUID = 1L;
	protected Node delegate;

	// Constructors
	/**
	 * Default NodeDelegate constructor.
	 *
	 * @pre <i>None</i>
	 * @post <pre>
	 * delegate = Node.NULL_NODE
	 * </pre>
	 */
	public NodeDelegate() {
		delegate = Node.NULL_NODE;
	}
	/**
	 * Returns whether this NodeDelegate is equal to the object passed in.
	 *
	 * @pre <i>None</i>
	 * @post result is true only if object &ne; null AND <br>
	 *                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	 *                object instanceof NodeDelegate AND <br>
	 *                this NodeDelegate is equal to the obj passed in.
	 */
	public boolean equals(Object obj) {
		return this.equals((NodeDelegate) obj);
	}
	/**
	 * Returns whether the delegate is equal to the NodeDelegate passed in.
	 *
	 * @pre <i>None</i>
	 * @post result is true only if object &ne; null AND <br>
	 *                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	 *                object instanceof Node AND <br>
	 *                node's delegate is equal to this delegate.
	 */
	public boolean equals(NodeDelegate node) {
		return delegate.getWebId().equals(node.delegate.getWebId());
	}
	/**
	 * Returns a string representation of the delegate.
	 * 
	 * @pre <i>None</i>
	 * @post result = delegate.webId.getValue() converted to a string.
	 */
	public String toString() {
		return delegate + "";
	}
	/**
	 * Abstract method implemented in each of the roles of a node within which a node is added in relation to the delegate.
	 *   
	 * @pre delegate.connections does not contain <b>node</b>.
	 * @post delegate.connections + <b>node</b>
	 */
	public abstract void add(Node node);
	/**
	 * Abstract method implemented in each of the roles of a node within which a node is removed in relation to the delegate.
	 *   
	 * @pre <b>node</b> !=NULL AND<br>
	 * <b>node</b> is an element of delegate.connections
	 * @post delegate.connections - <b>node</b>
	 */
	public abstract void remove(Node node);
	/**
	 * Abstract method implemented in each of the roles of a node within which node is replaced by the replacingNode in relation to the delegate.
	 *   
	 * @pre <b>node</b> is an element of delegate.connections AND<br>
	 * <b>replacingNode</b> is not an element of the delegate.connections
	 * @post <b>replacingNode</b> is an element of delegate.connections AND<br>
	 * <b>node</b> is not an element of the delegate.connections
	 */
	public abstract void replace(Node node, Node replacingNode);
	/**
	 * Returns the delegate.
	 * 
	 * @pre <i>None</i>
	 * @post result = this.delegate
	 */
	public Node getDelegate() {
		return delegate;
	}
	public void migrateNode(Node node, Node doesNothing) {
		delegate = node;
	}
}